package com.justnow.offer.q1;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo {

    //用于判断线程一是否执行，倒计时设置为1，执行countDown方法后减一

    private static CountDownLatch c1 = new CountDownLatch(1);

    //用于判断线程一是否执行，倒计时设置为1，执行countDown方法后减一
    private static CountDownLatch c2 = new CountDownLatch(1);

    public static void main(String[] args) {
        Thread a = new Thread(() -> {
            System.out.println("A");
            c1.countDown();
        });

        Thread b = new Thread(() -> {
            try {
                c1.await();
                System.out.println("B");
                c2.countDown();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        Thread c = new Thread(() -> {
            try {
                c2.await();
                System.out.println("C");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        a.start();
        b.start();
        c.start();
    }


}
